package org.jeecg.jxc.base.goods.service.impl;

import org.jeecg.jxc.base.goods.entity.Goods;
import org.jeecg.jxc.base.goods.entity.Unit;
import org.jeecg.jxc.base.goods.mapper.GoodsMapper;
import org.jeecg.jxc.base.goods.service.GoodsService;
import org.jeecg.jxc.base.goods.service.GoodsTypeService;
import org.jeecg.jxc.base.goods.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : luojin
 * @date : 2022/4/26 19:29
 */
@Service
public class GoodsServiceImpl implements GoodsService {
    @Resource
    private GoodsMapper goodsMapper;
    public List<Unit> getUnitList() {
        List<Unit> unitList=goodsMapper.selectUnit();
        return unitList;
    }
    @Transactional
    public PageVo<Goods> pageGoods(Integer pageNo, Integer pageSize, String goodsName, Integer goodsTypeId) {

        List<Goods> goodsList=goodsMapper.pageGoods((pageNo-1)*pageSize,pageSize,goodsName,goodsTypeId);

        Integer count=goodsMapper.pageGoodsCount((pageNo-1)*pageSize,pageSize,goodsName,goodsTypeId);
        PageVo<Goods> pageVo = new PageVo<>();
        pageVo.setList(goodsList);
        pageVo.setTotal(count);
        return pageVo;
    }

    @Override
    public boolean addGoods(Goods goods) {
        int insert = goodsMapper.insert(goods);
        return insert>0?true:false;
    }

    @Override
    public boolean delGoods(Integer goodsId) {
        int i = goodsMapper.deleteByPrimaryKey(goodsId);
        return i>0?true:false;
    }

    @Override
    public boolean updateGoods(Goods goods) {
        int i = goodsMapper.updateByPrimaryKeySelective(goods);
        return i>0?true:false;
    }
}
